package com.red.star.wechat.data.mappers;

import com.red.star.wechat.data.core.base.MyMapper;
import com.red.star.wechat.data.entity.Activity;
import com.red.star.wechat.data.entity.CustomerInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * @author nofish.yan@gmail.com
 * @date 2018/7/12.
 * 客户信息数据访问接口
 */
public interface CustomerInfoMapper extends MyMapper<CustomerInfo> {

    List<CustomerInfo> findCustomerInfoByEmployee(@Param("fansId") Integer fansId,
                                                  @Param("dateStartTime") Date dateStartTime,
                                                  @Param("dateEndTime") Date dateEndTime,
                                                  @Param("activityId") Integer activityId,
                                                  @Param("communicateStatus") String communicateStatus,
                                                  @Param("start") Integer start,
                                                  @Param("length") Integer length);

    List<CustomerInfo> findCustomerInfoByFactory(@Param("mobile") String mobile,
                                                 @Param("dateStartTime") Date dateStartTime,
                                                 @Param("dateEndTime") Date dateEndTime,
                                                 @Param("activityId") Integer activityId,
                                                 @Param("communicateStatus") String communicateStatus,
                                                 @Param("start") Integer start,
                                                 @Param("length") Integer length);

    Integer countCustomerInfoByEmployee(@Param("fansId") Integer fansId,
                                        @Param("dateStartTime") Date dateStartTime,
                                        @Param("dateEndTime") Date dateEndTime,
                                        @Param("activityId") Integer activityId,
                                        @Param("communicateStatus") String communicateStatus);

    Integer countCustomerInfoByFactory(@Param("mobile") String mobile,
                                       @Param("dateStartTime") Date dateStartTime,
                                       @Param("dateEndTime") Date dateEndTime,
                                       @Param("activityId") Integer activityId,
                                       @Param("communicateStatus") String communicateStatus);

    List<CustomerInfo> findCustomerInfoList(CustomerInfo customerInfo);

    void updateDeleteCustomerInfoById(@Param("id") Integer id);

    @Select(value = "SELECT count(id) from t_customer_info tc where tc.mobile =#{mobile} and  tc.intent_mall=#{intentMall} and tc.intent_brand=#{intentBrand} and tc.communicate_status=#{communicateStatus} and status=0")
    int selectCountCustomerInfo(CustomerInfo customerInfo);

    CustomerInfo selectById(Integer customerInfoId);

    /**
     * 查询所有客户及推送记录（导出用）
     * @param customerInfo
     * @return
     */
    List<CustomerInfo> selectCustomerInfo(CustomerInfo customerInfo);

    /**
     * 查询所有客户及推送记录（分页用）
     * @param customerInfo
     * @return
     */
    List<CustomerInfo> selectCustomerInfoPage(CustomerInfo customerInfo);

    @Select(value = "SELECT * from t_customer_info where push_mobile=#{pushMobile} and status=0 and push_status=1")
    List<CustomerInfo> selectByPushMobile(String pushMobile);

    List<Activity> listByEmployee(@Param("fansId") Integer fansId);

    List<Activity> listByFactory(@Param("mobile") String mobile);


}
